// pages/sale/index/index.js
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var user = require('../../../utils/user.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order: {
      unconfirm: 0,//待确认
      unpaid: 0, //待付款
      unship: 0,  //待发货
      recv: 0,  //已收货
      deliver: 0, //已发货
    }
  },
  // 跳转到销售列表页
  goSaleOrder: function(e){
    let index=e.currentTarget.dataset.index;
    wx.setStorageSync('index', index);
    console.log(index);
    if (app.globalData.hasLogin) {
      wx.navigateTo({
        url: '/pages/sale/orderList/orderList?index=' + index,
        success: function (res) { },
        fail: function (res) { },
        complete: function (res) { },
      })
    } else {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
    }
    
  },
  getSalesAmout:function(){
    util.request(api.Authsales,{},'POST').then(res => {
      if(res.errno == 0){
        this.setData({
          allSales: res.data.allSales,
          monthSales: res.data.monthSales,
          teamSales: res.data.teamSales,
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log(12313132)
    let that = this;
    util.request(api.UserIndex, { status:'sale'}).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          order: res.data.order
        });
      }
    });
    that.getSalesAmout()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})